简体   繁体   English

在 php 中使用 php-ai/php-ml

[英]Using php-ai/php-ml with php

I am using notepad++.我正在使用记事本++。 I have installed composer and from command line I have tried to install the php-ai/php-ml using the following line of code composer require php-ai/php-ml .我已经安装了 composer 并从命令行我尝试使用以下代码行安装 php-ai/php-ml composer require php-ai/php-ml My cmd tells me that this is successfully installed and everything seems okay.我的 cmd 告诉我这已成功安装并且一切正常。

However, in my index.php file if I try to use any of the libraries in the package php-ai/php-ml for example: use Phpml\\Dataset\\CsvDataset;但是,在我的 index.php 文件中,如果我尝试使用 php-ai/php-ml 包中的任何库,例如: use Phpml\\Dataset\\CsvDataset; I get the following error:我收到以下错误:

Fatal error: Uncaught Error: Class 'Phpml\\Dataset\\CsvDataset' not found in C:\\xampp\\htdocs\\test\\index.php:5 Stack trace: #0 {main} thrown in C:\\xampp\\htdocs\\test\\index.php on line 5致命错误:未捕获的错误:在 C:\\xampp\\htdocs\\test\\index.php:5 中找不到类 'Phpml\\Dataset\\CsvDataset' 堆栈跟踪:#0 {main} 抛出在 C:\\xampp\\htdocs\\test\\第 5 行的 index.php

Line 5 is the line which i request to use the library.第 5 行是我请求使用库的行。 Do i have to import these libraries or anything?我是否必须导入这些库或任何东西?

Composer files are dependecies for the project, so what you should do is: Composer 文件是项目的依赖,所以你应该做的是:

  1. Move the composer.json and composer.lock file to the same folder as your index.php.将 composer.json 和 composer.lock 文件移动到 index.php 所在的文件夹中。
  2. Open a command line window, go to that folder and run: "composer install".打开命令行窗口,转到该文件夹​​并运行:“composer install”。 That will create the "vendor" folder, download all dependencies and create an autoload.php in your project folder.这将创建“vendor”文件夹,下载所有依赖项并在您的项目文件夹中创建一个 autoload.php。
  3. Now you can put require __DIR__ . '/vendor/autoload.php'现在您可以放置require __DIR__ . '/vendor/autoload.php' require __DIR__ . '/vendor/autoload.php' in the top of your index.php require __DIR__ . '/vendor/autoload.php'在你的 index.php 的顶部

Have you required the vendor/autoload.php file first in your script?您是否首先需要在您的脚本中使用 vendor/autoload.php 文件? This is required to auto load the classes from composer.这是从作曲家自动加载类所必需的。

<?php

require 'vendor/autoload.php';

use Phpml\Dataset\CsvDataset;

$csv = new CsvDataset();

我认为您需要使用 Composer 在项目根目录中安装开发需求

bin/phpunit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM